const path = require('path')
const Koa = require('koa')
const cors = require('koa2-cors')

const router=require('../router/index')
const KoaBody=require('koa-body')
const KoaStatic=require('koa-static')
const errHandle=require('./errHandle')
const parameter=require('koa-parameter')
const app =new Koa()

app.use(KoaBody({
    multipart:true,
    formidable:{
        uploadDir:path.join(path.join(__dirname,'../uploadImage')),
        keepExtensions:true
    },
    //可以获取到参数，不加的默认只有常用的

    parsedMethods:['POST','PATCH','GET','DELETE','PUT']

}))
    app.use(KoaStatic(path.join(__dirname,'../uploadImage')))
app.use(parameter(app))
app.use(cors())
app.use(router.routes()).use(router.allowedMethods())

//统一的错误处理
app.on('error',errHandle)
module.exports=app